package appliance_1;

import java.util.Scanner;

interface Appliance{

    int weight();
}

class TV implements Appliance{
    int weight;

    TV(int weight) {
        this.weight = weight;
    }

    public int weight() {
        return weight;
    }
}

class WashMachine implements Appliance{
    int weight;

    WashMachine(int weight) {
        this.weight = weight;
    }

    public int weight() {
        return weight;
    }

}

class AirConditioner implements Appliance{
    int weight;

    AirConditioner(int weight) {
        this.weight = weight;
    }

    public int weight() {
        return weight;
    }
}

class Truck{
    int sum = 0;
    void add(Appliance appliance){
        sum += appliance.weight();
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        Truck truck = new Truck();
        int n = reader.nextInt();
        int k ,w;
        for (int i = 0; i < n; i++) {
            k = reader.nextInt();
            w = reader.nextInt();
            Appliance[]appliances = new Appliance[]{new TV(w),new AirConditioner(w),new WashMachine(w)};
            truck.add(appliances[k-1]);
        }

        System.out.println(truck.sum);
    }
}
